<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>LCOV - Lua 5.2.4 - src/ldump.c</title>
  <link rel="stylesheet" type="text/css" href="../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LCOV - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../index.html">top level</a> - <a href="index.html">src</a> - ldump.c</td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">Lua 5.2.4</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntry">94</td>
            <td class="headerCovTableEntry">94</td>
            <td class="headerCovTableEntryHi">100.0 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2019-06-13 19:44:16</td>
            <td></td>
          </tr>
          <tr>
            <td class="headerItem">Legend:</td>
            <td class="headerValueLeg">            Lines:
            <span class="coverLegendCov">hit</span>
            <span class="coverLegendNoCov">not hit</span>
</td>
            <td></td>
          </tr>
          <tr><td><img src="../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">          Line data    Source code</pre>
<pre class="source">
<span class="lineNum">       1 </span>            : /*
<span class="lineNum">       2 </span>            : ** $Id: ldump.c,v 2.17.1.1 2013/04/12 18:48:47 roberto Exp $
<span class="lineNum">       3 </span>            : ** save precompiled Lua chunks
<span class="lineNum">       4 </span>            : ** See Copyright Notice in lua.h
<span class="lineNum">       5 </span>            : */
<span class="lineNum">       6 </span>            : 
<span class="lineNum">       7 </span>            : #include &lt;stddef.h&gt;
<span class="lineNum">       8 </span>            : 
<span class="lineNum">       9 </span>            : #define ldump_c
<span class="lineNum">      10 </span>            : #define LUA_CORE
<span class="lineNum">      11 </span>            : 
<span class="lineNum">      12 </span>            : #include &quot;lua.h&quot;
<span class="lineNum">      13 </span>            : 
<span class="lineNum">      14 </span>            : #include &quot;lobject.h&quot;
<span class="lineNum">      15 </span>            : #include &quot;lstate.h&quot;
<span class="lineNum">      16 </span>            : #include &quot;lundump.h&quot;
<span class="lineNum">      17 </span>            : 
<span class="lineNum">      18 </span>            : typedef struct {
<span class="lineNum">      19 </span>            :  lua_State* L;
<span class="lineNum">      20 </span>            :  lua_Writer writer;
<span class="lineNum">      21 </span>            :  void* data;
<span class="lineNum">      22 </span>            :  int strip;
<span class="lineNum">      23 </span>            :  int status;
<span class="lineNum">      24 </span>            : } DumpState;
<span class="lineNum">      25 </span>            : 
<span class="lineNum">      26 </span>            : #define DumpMem(b,n,size,D)     DumpBlock(b,(n)*(size),D)
<span class="lineNum">      27 </span>            : #define DumpVar(x,D)            DumpMem(&amp;x,1,sizeof(x),D)
<span class="lineNum">      28 </span>            : 
<span class="lineNum">      29 </span><span class="lineCov">        528 : static void DumpBlock(const void* b, size_t size, DumpState* D)</span>
<span class="lineNum">      30 </span>            : {
<span class="lineNum">      31 </span><span class="lineCov">        528 :  if (D-&gt;status==0)</span>
<span class="lineNum">      32 </span>            :  {
<span class="lineNum">      33 </span>            :   lua_unlock(D-&gt;L);
<span class="lineNum">      34 </span><span class="lineCov">        528 :   D-&gt;status=(*D-&gt;writer)(D-&gt;L,b,size,D-&gt;data);</span>
<span class="lineNum">      35 </span>            :   lua_lock(D-&gt;L);
<span class="lineNum">      36 </span>            :  }
<span class="lineNum">      37 </span><span class="lineCov">        528 : }</span>
<span class="lineNum">      38 </span>            : 
<span class="lineNum">      39 </span><span class="lineCov">        146 : static void DumpChar(int y, DumpState* D)</span>
<span class="lineNum">      40 </span>            : {
<span class="lineNum">      41 </span><span class="lineCov">        146 :  char x=(char)y;</span>
<span class="lineNum">      42 </span><span class="lineCov">        146 :  DumpVar(x,D);</span>
<span class="lineNum">      43 </span><span class="lineCov">        146 : }</span>
<span class="lineNum">      44 </span>            : 
<span class="lineNum">      45 </span><span class="lineCov">        161 : static void DumpInt(int x, DumpState* D)</span>
<span class="lineNum">      46 </span>            : {
<span class="lineNum">      47 </span><span class="lineCov">        161 :  DumpVar(x,D);</span>
<span class="lineNum">      48 </span><span class="lineCov">        161 : }</span>
<span class="lineNum">      49 </span>            : 
<span class="lineNum">      50 </span><span class="lineCov">          7 : static void DumpNumber(lua_Number x, DumpState* D)</span>
<span class="lineNum">      51 </span>            : {
<span class="lineNum">      52 </span><span class="lineCov">          7 :  DumpVar(x,D);</span>
<span class="lineNum">      53 </span><span class="lineCov">          7 : }</span>
<span class="lineNum">      54 </span>            : 
<span class="lineNum">      55 </span><span class="lineCov">         30 : static void DumpVector(const void* b, int n, size_t size, DumpState* D)</span>
<span class="lineNum">      56 </span>            : {
<span class="lineNum">      57 </span><span class="lineCov">         30 :  DumpInt(n,D);</span>
<span class="lineNum">      58 </span><span class="lineCov">         30 :  DumpMem(b,n,size,D);</span>
<span class="lineNum">      59 </span><span class="lineCov">         30 : }</span>
<span class="lineNum">      60 </span>            : 
<span class="lineNum">      61 </span><span class="lineCov">         89 : static void DumpString(const TString* s, DumpState* D)</span>
<span class="lineNum">      62 </span>            : {
<span class="lineNum">      63 </span><span class="lineCov">         89 :  if (s==NULL)</span>
<span class="lineNum">      64 </span>            :  {
<span class="lineNum">      65 </span><span class="lineCov">          4 :   size_t size=0;</span>
<span class="lineNum">      66 </span><span class="lineCov">          4 :   DumpVar(size,D);</span>
<span class="lineNum">      67 </span>            :  }
<span class="lineNum">      68 </span>            :  else
<span class="lineNum">      69 </span>            :  {
<span class="lineNum">      70 </span><span class="lineCov">         85 :   size_t size=s-&gt;tsv.len+1;          /* include trailing '\0' */</span>
<span class="lineNum">      71 </span><span class="lineCov">         85 :   DumpVar(size,D);</span>
<span class="lineNum">      72 </span><span class="lineCov">         85 :   DumpBlock(getstr(s),size*sizeof(char),D);</span>
<span class="lineNum">      73 </span>            :  }
<span class="lineNum">      74 </span><span class="lineCov">         89 : }</span>
<span class="lineNum">      75 </span>            : 
<span class="lineNum">      76 </span>            : #define DumpCode(f,D)    DumpVector(f-&gt;code,f-&gt;sizecode,sizeof(Instruction),D)
<span class="lineNum">      77 </span>            : 
<span class="lineNum">      78 </span>            : static void DumpFunction(const Proto* f, DumpState* D);
<span class="lineNum">      79 </span>            : 
<span class="lineNum">      80 </span><span class="lineCov">         15 : static void DumpConstants(const Proto* f, DumpState* D)</span>
<span class="lineNum">      81 </span>            : {
<span class="lineNum">      82 </span><span class="lineCov">         15 :  int i,n=f-&gt;sizek;</span>
<span class="lineNum">      83 </span><span class="lineCov">         15 :  DumpInt(n,D);</span>
<span class="lineNum">      84 </span><span class="lineCov">         73 :  for (i=0; i&lt;n; i++)</span>
<span class="lineNum">      85 </span>            :  {
<span class="lineNum">      86 </span><span class="lineCov">         58 :   const TValue* o=&amp;f-&gt;k[i];</span>
<span class="lineNum">      87 </span><span class="lineCov">         58 :   DumpChar(ttypenv(o),D);</span>
<span class="lineNum">      88 </span><span class="lineCov">         58 :   switch (ttypenv(o))</span>
<span class="lineNum">      89 </span>            :   {
<span class="lineNum">      90 </span><span class="lineCov">          3 :    case LUA_TNIL:</span>
<span class="lineNum">      91 </span><span class="lineCov">          3 :         break;</span>
<span class="lineNum">      92 </span><span class="lineCov">          3 :    case LUA_TBOOLEAN:</span>
<span class="lineNum">      93 </span><span class="lineCov">          3 :         DumpChar(bvalue(o),D);</span>
<span class="lineNum">      94 </span><span class="lineCov">          3 :         break;</span>
<span class="lineNum">      95 </span><span class="lineCov">          7 :    case LUA_TNUMBER:</span>
<span class="lineNum">      96 </span><span class="lineCov">          7 :         DumpNumber(nvalue(o),D);</span>
<span class="lineNum">      97 </span><span class="lineCov">          7 :         break;</span>
<span class="lineNum">      98 </span><span class="lineCov">         45 :    case LUA_TSTRING:</span>
<span class="lineNum">      99 </span><span class="lineCov">         45 :         DumpString(rawtsvalue(o),D);</span>
<span class="lineNum">     100 </span><span class="lineCov">         45 :         break;</span>
<span class="lineNum">     101 </span><span class="lineCov">         58 :     default: lua_assert(0);</span>
<span class="lineNum">     102 </span>            :   }
<span class="lineNum">     103 </span>            :  }
<span class="lineNum">     104 </span><span class="lineCov">         15 :  n=f-&gt;sizep;</span>
<span class="lineNum">     105 </span><span class="lineCov">         15 :  DumpInt(n,D);</span>
<span class="lineNum">     106 </span><span class="lineCov">         20 :  for (i=0; i&lt;n; i++) DumpFunction(f-&gt;p[i],D);</span>
<span class="lineNum">     107 </span><span class="lineCov">         15 : }</span>
<span class="lineNum">     108 </span>            : 
<span class="lineNum">     109 </span><span class="lineCov">         15 : static void DumpUpvalues(const Proto* f, DumpState* D)</span>
<span class="lineNum">     110 </span>            : {
<span class="lineNum">     111 </span><span class="lineCov">         15 :  int i,n=f-&gt;sizeupvalues;</span>
<span class="lineNum">     112 </span><span class="lineCov">         15 :  DumpInt(n,D);</span>
<span class="lineNum">     113 </span><span class="lineCov">         35 :  for (i=0; i&lt;n; i++)</span>
<span class="lineNum">     114 </span>            :  {
<span class="lineNum">     115 </span><span class="lineCov">         20 :   DumpChar(f-&gt;upvalues[i].instack,D);</span>
<span class="lineNum">     116 </span><span class="lineCov">         20 :   DumpChar(f-&gt;upvalues[i].idx,D);</span>
<span class="lineNum">     117 </span>            :  }
<span class="lineNum">     118 </span><span class="lineCov">         15 : }</span>
<span class="lineNum">     119 </span>            : 
<span class="lineNum">     120 </span><span class="lineCov">         15 : static void DumpDebug(const Proto* f, DumpState* D)</span>
<span class="lineNum">     121 </span>            : {
<span class="lineNum">     122 </span>            :  int i,n;
<span class="lineNum">     123 </span><span class="lineCov">         15 :  DumpString((D-&gt;strip) ? NULL : f-&gt;source,D);</span>
<span class="lineNum">     124 </span><span class="lineCov">         15 :  n= (D-&gt;strip) ? 0 : f-&gt;sizelineinfo;</span>
<span class="lineNum">     125 </span><span class="lineCov">         15 :  DumpVector(f-&gt;lineinfo,n,sizeof(int),D);</span>
<span class="lineNum">     126 </span><span class="lineCov">         15 :  n= (D-&gt;strip) ? 0 : f-&gt;sizelocvars;</span>
<span class="lineNum">     127 </span><span class="lineCov">         15 :  DumpInt(n,D);</span>
<span class="lineNum">     128 </span><span class="lineCov">         28 :  for (i=0; i&lt;n; i++)</span>
<span class="lineNum">     129 </span>            :  {
<span class="lineNum">     130 </span><span class="lineCov">         13 :   DumpString(f-&gt;locvars[i].varname,D);</span>
<span class="lineNum">     131 </span><span class="lineCov">         13 :   DumpInt(f-&gt;locvars[i].startpc,D);</span>
<span class="lineNum">     132 </span><span class="lineCov">         13 :   DumpInt(f-&gt;locvars[i].endpc,D);</span>
<span class="lineNum">     133 </span>            :  }
<span class="lineNum">     134 </span><span class="lineCov">         15 :  n= (D-&gt;strip) ? 0 : f-&gt;sizeupvalues;</span>
<span class="lineNum">     135 </span><span class="lineCov">         15 :  DumpInt(n,D);</span>
<span class="lineNum">     136 </span><span class="lineCov">         31 :  for (i=0; i&lt;n; i++) DumpString(f-&gt;upvalues[i].name,D);</span>
<span class="lineNum">     137 </span><span class="lineCov">         15 : }</span>
<span class="lineNum">     138 </span>            : 
<span class="lineNum">     139 </span><span class="lineCov">         15 : static void DumpFunction(const Proto* f, DumpState* D)</span>
<span class="lineNum">     140 </span>            : {
<span class="lineNum">     141 </span><span class="lineCov">         15 :  DumpInt(f-&gt;linedefined,D);</span>
<span class="lineNum">     142 </span><span class="lineCov">         15 :  DumpInt(f-&gt;lastlinedefined,D);</span>
<span class="lineNum">     143 </span><span class="lineCov">         15 :  DumpChar(f-&gt;numparams,D);</span>
<span class="lineNum">     144 </span><span class="lineCov">         15 :  DumpChar(f-&gt;is_vararg,D);</span>
<span class="lineNum">     145 </span><span class="lineCov">         15 :  DumpChar(f-&gt;maxstacksize,D);</span>
<span class="lineNum">     146 </span><span class="lineCov">         15 :  DumpCode(f,D);</span>
<span class="lineNum">     147 </span><span class="lineCov">         15 :  DumpConstants(f,D);</span>
<span class="lineNum">     148 </span><span class="lineCov">         15 :  DumpUpvalues(f,D);</span>
<span class="lineNum">     149 </span><span class="lineCov">         15 :  DumpDebug(f,D);</span>
<span class="lineNum">     150 </span><span class="lineCov">         15 : }</span>
<span class="lineNum">     151 </span>            : 
<span class="lineNum">     152 </span><span class="lineCov">         10 : static void DumpHeader(DumpState* D)</span>
<span class="lineNum">     153 </span>            : {
<span class="lineNum">     154 </span>            :  lu_byte h[LUAC_HEADERSIZE];
<span class="lineNum">     155 </span><span class="lineCov">         10 :  luaU_header(h);</span>
<span class="lineNum">     156 </span><span class="lineCov">         10 :  DumpBlock(h,LUAC_HEADERSIZE,D);</span>
<span class="lineNum">     157 </span><span class="lineCov">         10 : }</span>
<span class="lineNum">     158 </span>            : 
<span class="lineNum">     159 </span>            : /*
<span class="lineNum">     160 </span>            : ** dump Lua function as precompiled chunk
<span class="lineNum">     161 </span>            : */
<span class="lineNum">     162 </span><span class="lineCov">         10 : int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip)</span>
<span class="lineNum">     163 </span>            : {
<span class="lineNum">     164 </span>            :  DumpState D;
<span class="lineNum">     165 </span><span class="lineCov">         10 :  D.L=L;</span>
<span class="lineNum">     166 </span><span class="lineCov">         10 :  D.writer=w;</span>
<span class="lineNum">     167 </span><span class="lineCov">         10 :  D.data=data;</span>
<span class="lineNum">     168 </span><span class="lineCov">         10 :  D.strip=strip;</span>
<span class="lineNum">     169 </span><span class="lineCov">         10 :  D.status=0;</span>
<span class="lineNum">     170 </span><span class="lineCov">         10 :  DumpHeader(&amp;D);</span>
<span class="lineNum">     171 </span><span class="lineCov">         10 :  DumpFunction(f,&amp;D);</span>
<span class="lineNum">     172 </span><span class="lineCov">         10 :  return D.status;</span>
<span class="lineNum">     173 </span>            : }
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.13</a></td></tr>
  </table>
  <br>

</body>
</html>
